package cin.ufpe.br.GDI.Dados;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import cin.ufpe.br.GDI.Entidades.Edicao;

public class RepositorioEdicao {
	
	private Connection conn;
	
	public RepositorioEdicao (Connection conn){
		this.conn = conn;
	}
	
	public Vector<Edicao> getEdicoes() throws SQLException{
		
		Statement statement = conn.createStatement();
		ResultSet rs;
		
		Vector<Edicao> edicoes = new Vector<Edicao>();
		
		String queryEdicoes = "SELECT e.*, TO_CHAR(e.data_publicacao) AS data_publicacao FROM tb_edicao e";
		
		rs = statement.executeQuery(queryEdicoes);
		
		while(rs.next()){
			
			int numero = rs.getInt("numero");
			String manchete = rs.getString("manchete");
			String data_publicacao = rs.getString("data_publicacao");
			
			edicoes.add(new Edicao(numero, manchete, data_publicacao));
		}
		
		return edicoes;
	}
	
	/*public static void main(String args[]){
		
		ConexaoBD con = new ConexaoBD();
		try {
			con.conectarBD();
			
			RepositorioEdicao repEdicao = new RepositorioEdicao(con.getConn());
			
			Vector<Edicao> e = repEdicao.getEdicaos();
			
			for(Edicao edicao: e){
				System.out.println(edicao);
			}
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}*/

}
